// 监听post 请求和 处理post 数据
var http = require('http')
var querystring = require('querystring')

var server = http.createServer().listen(3000)

server.on('request', (req, res) => {
  let method = req.method
  console.log(method)
  if(req.method == 'POST'){
    let body = ''
    // append data chunk to body
    req.on('data', (data) => {
      body += data
    })

    // data transmitted
    req.on('end', () => {
      let post = querystring.parse(body)
      console.log(post)
      res.writeHead(200, {'Content-Type': 'text/plain'})
      res.end('DUUOO')
    })
  }else{
    res.writeHead(200, {'Content-Type': 'text/plain'})
    res.end('other method:' + method)
  }
})

console.log('server runing')